package com.study.bookstore.service.impl;

import com.study.bookstore.domain.Author;
import com.study.bookstore.domain.BookType;
import com.study.bookstore.service.BookBasicService;
import com.study.bookstore.domain.BookBasic;
import com.study.bookstore.repository.BookBasicRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Service Implementation for managing BookBasic.
 */
@Service
@Transactional
public class BookBasicServiceImpl implements BookBasicService {

    private final Logger log = LoggerFactory.getLogger(BookBasicServiceImpl.class);

    private final BookBasicRepository bookBasicRepository;

    public BookBasicServiceImpl(BookBasicRepository bookBasicRepository) {
        this.bookBasicRepository = bookBasicRepository;
    }

    /**
     * Save a bookBasic.
     *
     * @param bookBasic the entity to save
     * @return the persisted entity
     */
    @Override
    public BookBasic save(BookBasic bookBasic) {
        log.debug("Request to save BookBasic : {}", bookBasic);
        return bookBasicRepository.save(bookBasic);
    }

    /**
     * Get all the bookBasics.
     *
     * @param pageable the pagination information
     * @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<BookBasic> findAll(Pageable pageable) {
        log.debug("Request to get all BookBasics");
        return bookBasicRepository.findAll(pageable);
    }

    /**
     * Get one bookBasic by id.
     *
     * @param id the id of the entity
     * @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public BookBasic findOne(Long id) {
        log.debug("Request to get BookBasic : {}", id);
        return bookBasicRepository.findOne(id);
    }

    /**
     * Delete the bookBasic by id.
     *
     * @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete BookBasic : {}", id);
        bookBasicRepository.delete(id);
    }

    @Override
    public Page<BookBasic> findBookBasicLike(Integer type,String keyword, Pageable pageable) throws Exception {
        return bookBasicRepository.findBookBasicLike(type,keyword,pageable);
    }

    @Override
    public Page<BookBasic> findBookBasicByBookTypeId(BookType bookType, Pageable pageable) throws Exception {
        return bookBasicRepository.findBookBasicsByBookTypeIdOrderByIdDesc(bookType, pageable);
    }

    @Override
    public Page<BookBasic> findBookBasicsByAuthodId(Author author, Pageable pageable) throws Exception {
        return bookBasicRepository.findBookBasicsByAuthodIdOrderByIdAsc(author, pageable);
    }
}
